package com.a.xposedemome;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
    private static final String TAG = "dhy_MainActivity";

    Button ChangeButton = null;
    Button showButton = null;
    Button clearButton = null;
    EditText imeiEditText = null;
    EditText macEditText = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imeiEditText = (EditText) findViewById(R.id.editTextIMEI);
        macEditText = (EditText) findViewById(R.id.editTextMAC);
        ChangeButton = (Button) findViewById(R.id.button_change);
        showButton = (Button) findViewById(R.id.button_show);
        clearButton = (Button) findViewById(R.id.button_clear);
        ChangeButton.setOnClickListener(new MyButtonClick());
        showButton.setOnClickListener(new MyButtonClick());
        clearButton.setOnClickListener(new MyButtonClick());
    }

    class MyButtonClick implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.button_change:
                    String imeiString = imeiEditText.getText() + "";
                    String macString = macEditText.getText() + "";

                    try {
                        if (!imeiString.trim().equals("")) {
                            PrivacyService.setValue("imei", imeiString);
                        } else {
                            Toast.makeText(MainActivity.this, "imei is null", Toast.LENGTH_SHORT).show();
                        }
                        if (!macString.trim().equals("")) {
                            PrivacyService.setValue("mac", macString);
                        } else {
                            Toast.makeText(MainActivity.this, "mac is null", Toast.LENGTH_SHORT).show();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case R.id.button_show:
                    TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
                    imeiEditText.setText(tManager.getDeviceId() + "");
                    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
                    if (null != wifiInfo) {
                        macEditText.setText(wifiInfo.getMacAddress());
                    } else {
                        macEditText.setText("null");
                    }
                    break;
                case R.id.button_clear:
                    imeiEditText.setText("");
                    macEditText.setText("");
                    break;
            }
        }

    }
}

